﻿<localControls:ImprovedChildWindow
	x:Class="Toon.Dialogs.PossessionPicker"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
	xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    xmlns:converters="clr-namespace:Granite.Xaml.Converters;assembly=Granite.Xaml"
	Width="700" Height="450" 
	xmlns:localControls="clr-namespace:Toon.Controls"
	Title="Possessions">
    <Grid x:Name="LayoutRoot" Margin="2">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>


            <StackPanel Margin="5" Grid.Column="0">
                <toolkit:DockPanel LastChildFill="False">
                    <TextBlock FontSize="20" Text="Catalog" VerticalAlignment="Center" toolkit:DockPanel.Dock="Left" />
                    <localControls:DetailRegion Margin="4" Command="{StaticResource RandomPick}" CommandParameter="{Binding Catalog.Possessions}" Background="Transparent">
                        <Button.Content>
                            <Image Stretch="Uniform" Width="40" Height="40" Source="/Toon;component/Assets/Die-1.png" />
                        </Button.Content>
                    </localControls:DetailRegion>
                    <localControls:DetailRegion Margin="4" Command="{StaticResource RandomPickAll}" CommandParameter="{Binding Catalog.Possessions}" Background="Transparent" >
                        <Button.Content>
                            <Image Stretch="Uniform" Width="40" Height="40" Source="/Toon;component/Assets/Die-3.png" />
                        </Button.Content>
                    </localControls:DetailRegion>
                </toolkit:DockPanel>
            </StackPanel>

            <ScrollViewer Grid.Row="1">
                <ItemsControl  ItemsSource="{Binding Catalog.Possessions}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <toolkit:Expander>
                                <toolkit:Expander.Header>
                                    <toolkit:DockPanel LastChildFill="False">
                                        <TextBlock Text="{Binding Name}" toolkit:DockPanel.Dock="Left"/>
                                        <localControls:DetailRegion Margin="4" Command="{StaticResource RandomPick}" CommandParameter="{Binding}" toolkit:DockPanel.Dock="Right" Background="Transparent">
                                            <Button.Content>
                                                <Image Stretch="Uniform" Width="25" Height="25" Source="/Toon;component/Assets/Die-1.png" />
                                            </Button.Content>
                                        </localControls:DetailRegion>
                                    </toolkit:DockPanel>
                                </toolkit:Expander.Header>

                                <ItemsControl ItemsSource="{Binding}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <localControls:DetailRegion Command="{StaticResource AddPossession}" CommandParameter="{Binding Item}" >
                                                <TextBlock Text="{Binding Name}" />
                                            </localControls:DetailRegion>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>

                                </ItemsControl>


                            </toolkit:Expander>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>


            <toolkit:DockPanel Margin="5" Grid.Column="1" LastChildFill="False">
                <TextBlock FontSize="20" Text="Possessions" VerticalAlignment="Center" HorizontalAlignment="Center" toolkit:DockPanel.Dock="Left" />
                <Button Content="New" Command="{StaticResource NewPossession}" VerticalAlignment="Center"  toolkit:DockPanel.Dock="Right"/>
            </toolkit:DockPanel>

            <ItemsControl Grid.Column="1" Grid.Row="1" ItemsSource="{Binding Possessions}"  >
                <ItemsControl.Template>
                    <ControlTemplate>
                        <ScrollViewer>
                            <ItemsPresenter />
                        </ScrollViewer>
                    </ControlTemplate>
                </ItemsControl.Template>
                <!-- If you virtualize this control you scroll by item. If you don't, then you scroll smoothly. -->
                <!--<ItemsControl.ItemsPanel>
					<ItemsPanelTemplate>
						<VirtualizingStackPanel />
					</ItemsPanelTemplate>
				</ItemsControl.ItemsPanel>-->
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>

                            <TextBox Margin="4" Text="{Binding Name, Mode=TwoWay}" Grid.ColumnSpan="2" />

                            <ToggleButton Margin="4" Content="Notes" Name="ShowNotes" Grid.Column="2" />

                            <CheckBox Margin="4" Grid.Column="3"
                                      VerticalAlignment="Center" HorizontalAlignment="Center"
									  IsChecked="{Binding Type, Mode=TwoWay, Converter={StaticResource UnusualCheckBox}}"
									  IsEnabled="{Binding Type, Converter={StaticResource UnusualCheckBoxIsEnabled}}" />

                            <Button VerticalAlignment="Center" HorizontalAlignment="Center" Width="20" Height="20" Margin="4" Content="-" Command="{StaticResource RemovePossession}" CommandParameter="{Binding}" Grid.Column="4"/>

                            <TextBlock Margin="4" Text="Notes" Grid.Row="1" 
                                       Visibility="{Binding IsChecked, ElementName=ShowNotes, Converter={StaticResource TrueToVisibleConverter}}"/>
                            <TextBox Margin="4" Text="{Binding Notes, Mode=TwoWay}" AcceptsReturn="True" Grid.Row="1" Grid.Column="1" Height="50" Grid.ColumnSpan="2" 
                                     Visibility="{Binding IsChecked, ElementName=ShowNotes, Converter={StaticResource TrueToVisibleConverter}}"/>

                        </Grid>

                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>


        </Grid>

        <Button Margin="8" Name="OKButton" Content="Close" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Center" Grid.Row="1" />
    </Grid>
</localControls:ImprovedChildWindow>
	
    